﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalcLibrary.Interface;

namespace CalcLibrary
{
    public class BasicCalculator : IBasicCalculator
    {
        public int Add(int a, int b)
        {
            return a + b;
        }

        public int Mul(int a, int b)
        {
            return a * b;
        }

        public int Div(int a, int b)
        {
            return a / b;
        }

        public int Sub(int a, int b)
        {
            return a - b;
        }


        //public int AddList(IEnumerable<int> listOfNumber)
        //{
        //    int retval = 0;
        //    foreach (var number in listOfNumber)
        //    {
        //        retval += number;
        //    }
        //    return retval;
        //}


        public int ComlpexListOperation(IEnumerable<int> listOfNumber, CalOperation calOp)
        {
            int retval = 0;
            foreach (int number in listOfNumber)
            {
                switch (calOp)
                {
                    case CalOperation.Add:
                        retval = this.Add(retval, number);
                        break;
                    case CalOperation.Mul:
                        retval = this.Mul(retval, number);
                        break;
                    case CalOperation.Sub:
                        retval = this.Sub(retval, number);
                        break;
                    case CalOperation.Div:
                        retval = this.Div(retval, number);
                        break;
                    default:
                        break;
                }

                
            }
            return retval;
        }
    }
}
